import { Component, OnInit } from '@angular/core';
import { WebInfoService } from '../service/webinfo.service';
import { NzModalService } from 'ng-zorro-antd/modal';
import { WebInfoEditComponent } from '../edit/edit.component';

@Component({
  selector: 'app-view',
  templateUrl: './view.component.html',
  styleUrls: ['./view.component.less'],
})
export class WebInfoViewComponent implements OnInit {
  data: any;

  constructor(private service: WebInfoService, private modal: NzModalService) {}

  ngOnInit(): void {
    this.load();
  }

  load(): void {
    this.service.latestInfo().subscribe((res) => {
      this.data = res.data;
    });
  }

  edit() {
    this.modal
      .create({
        nzContent: WebInfoEditComponent,
        nzComponentParams: {
          record: this.data,
        },
        nzTitle: '编辑信息',
        nzMaskClosable: true,
        nzFooter: null,
      })
      .afterClose.subscribe((res: any) => {
        if (res) {
          this.load();
        }
      });
  }
}
